<?php

/* @var $this yii\web\View */
/* @var $errorCode integer */
/* @var $title string */
/* @var $message string */
/* @var $previousPage string */
/* @var $exception Exception */
/* @var $redirectList array */
/* @var $reasons array */

use app\assets\BackendAsset as Asset;
Asset::register($this);
$this->title = $title;

Asset::addCss($this, '/css/error.css');
?>
<div id="doc_main" class="error-404">
    <section class="bd clearfix">
        <div class="module-error">
            <div class="error-main clearfix">
                <div class="label"></div>
                <div class="info">
                    <h3 class="title">错误(<?=$errorCode?>): <?= $message ?> </h3>
                    <div class="reason">
                        <p>可能的原因：</p>
                        <?php foreach ($reasons as $k => $v) { ?>
                        <p><?=$k + 1?>. <?=$v?></p>
                        <?php } ?>
                    </div>
                    <div class="oper">
                        <?php if ($errorCode == 401) { ?>
                            <div class="oper-item counter">
                                <i>5</i>秒后自动跳转到
                                <a href="javascript:void(0);" id="toLogin">登录&gt;</a>
                            </div>
                        <?php } else if (!isset($redirectList)) { ?>
                            <div class="oper-item">
                                <a href="javascript:void(0);" id="toIndex">工作台首页&gt;</a>
                            </div>
                        <?php } else if (is_array($redirectList)){
                            foreach ($redirectList as $k => $v) { ?>
                                <div class="oper-item">
                                    <a href="<?=$v?>"><?=$k?></a>
                                </div>
                            <?php }
                        } ?>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<?= Asset::addScript($this, "/js/jquery.min.js");?>
<?= Asset::addScript($this, "/js/common.js");?>
<?= $this->registerJs("
    if(self.frameElement === null) {
        jQuery('#toLogin').on('click', function() {
            window.location.href = \$w.getPageUrl('login') + '?showHint=' + 1;
        });
        jQuery('#toIndex').on('click', function() {
            window.location.href = \$w.getPageUrl('workBench');
        });
    } else {
        jQuery('#toLogin').on('click', function() {
            // 去登录
            window.top.window.instance.goToLogin();
        });
    }
");?>
<script>
    function cancel() {
        var isIframe = $w.getParams('is_iframe');
        if (+isIframe === 1 && window.parent.instance) {
            window.parent.instance.pageDialog.show = false;
        } else window.history.back();
    }
</script>
<?php if ($errorCode == 401) { // 403 开启JS倒计时
    $this->registerJs("
        var timer = 5;
        setInterval(function() {
            if (timer <= 1) {
                // 有登录跳转登录
                $('#toLogin').click();
                // 有首页跳转首页
                $('#toIndex').click();
            }
            $('.counter > i').text(timer);
            timer = timer - 1;
        }, 1000);
    ");
}?>
